package com.chiwen.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.chiwen.common.annotation.Log;
import com.chiwen.common.core.controller.BaseController;
import com.chiwen.common.core.domain.AjaxResult;
import com.chiwen.common.enums.BusinessType;
import com.chiwen.system.domain.SysPayway;
import com.chiwen.system.service.ISysPaywayService;
import com.chiwen.common.utils.poi.ExcelUtil;
import com.chiwen.common.core.page.TableDataInfo;

/**
 * 支付通道Controller
 * 
 * @author Dipepr
 * @date 2022-11-13
 */
@RestController
@RequestMapping("/system/syspayway")
public class SysPaywayController extends BaseController
{
    @Autowired
    private ISysPaywayService sysPaywayService;

    /**
     * 查询支付通道列表
     */
    @PreAuthorize("@ss.hasPermi('system:syspayway:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysPayway sysPayway)
    {
        startPage();
        List<SysPayway> list = sysPaywayService.selectSysPaywayList(sysPayway);
        return getDataTable(list);
    }

    /**
     * 导出支付通道列表
     */
    @PreAuthorize("@ss.hasPermi('system:syspayway:export')")
    @Log(title = "支付通道", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysPayway sysPayway)
    {
        List<SysPayway> list = sysPaywayService.selectSysPaywayList(sysPayway);
        ExcelUtil<SysPayway> util = new ExcelUtil<SysPayway>(SysPayway.class);
        util.exportExcel(response, list, "支付通道数据");
    }

    /**
     * 获取支付通道详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:syspayway:query')")
    @GetMapping(value = "/{wayId}")
    public AjaxResult getInfo(@PathVariable("wayId") Integer wayId)
    {
        return success(sysPaywayService.selectSysPaywayByWayId(wayId));
    }

    /**
     * 新增支付通道
     */
    @PreAuthorize("@ss.hasPermi('system:syspayway:add')")
    @Log(title = "支付通道", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysPayway sysPayway)
    {
        return toAjax(sysPaywayService.insertSysPayway(sysPayway));
    }

    /**
     * 修改支付通道
     */
    @PreAuthorize("@ss.hasPermi('system:syspayway:edit')")
    @Log(title = "支付通道", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysPayway sysPayway)
    {
        return toAjax(sysPaywayService.updateSysPayway(sysPayway));
    }

    /**
     * 删除支付通道
     */
    @PreAuthorize("@ss.hasPermi('system:syspayway:remove')")
    @Log(title = "支付通道", businessType = BusinessType.DELETE)
	@DeleteMapping("/{wayIds}")
    public AjaxResult remove(@PathVariable Integer[] wayIds)
    {
        return toAjax(sysPaywayService.deleteSysPaywayByWayIds(wayIds));
    }
}
